import time

from flask import Blueprint, request
import pymysql
from utilsapp import utils
from itertools import groupby
import datetime
from utilsapp.mysql_con import db_delete, db_insert, db_update, db_list, get_conn, db_table_pagelist
from dateutil.relativedelta import relativedelta

bluePrint = Blueprint('knowledge', __name__)
tableName = 'knowledge'


# 分页查询
@bluePrint.route('/getlist', methods=["post"])
def table_list():
    if 'page' in request.json.keys() and 'size' in request.json.keys():
        page = request.json['page']
        size = request.json['size']
    else:
        page = 1
        size = 999
    j = db_table_pagelist(tableName, page, '', size)
    return j


# 新增
@bluePrint.route('/add', methods=['POST'])
def table_add():
    return db_insert(tableName, request.json)


# 删除
@bluePrint.route('/delete', methods=["post"])
def table_delete():
    id = request.json['id']
    return db_delete(tableName, f'WHERE id=%s', {'id': id})